package acm.pta7;

import java.io.*;
import java.util.*;

public class Main {

    static int N = (int) 1e4;
    static ArrayList<Integer> map[] = new ArrayList[N + 10]; // 存储城市
    static boolean vis[] = new boolean[N + 10]; // 标记当前城市是否被攻击
    static int n, m;

    static boolean check() {
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < map[i].size(); j++) {
                //当前城市没有被攻击且相邻国家也没有被攻击
                if (!vis[i] && !vis[map[i].get(j)])
                    return false;
            }
        }
        return true;
    }

    public static void main(String[] args) throws IOException {
        Reader sc=new Reader();
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i <= n; i++)
            map[i] = new ArrayList<Integer>();

        while (m-- > 0) {
            int a =sc.nextInt(), b =sc.nextInt();
            map[a].add(b);
            map[b].add(a);
        }

        int k = sc.nextInt();
        while (k-- > 0) {
            int np =sc.nextInt();
            vis = new boolean[n + 10];
            while (np-- > 0) {
                int v =sc.nextInt();
                vis[v] = true; // 当前城市被攻打了
            }
            System.out.println(check() ? "YES" : "NO");
        }
    }
    static class Reader {
        private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer tokenizer = new StringTokenizer("");

        private String innerNextLine() {
            try {
                return reader.readLine();
            } catch (IOException ex) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!tokenizer.hasMoreTokens()) {    //内存中没有
                String nextLine = innerNextLine();
                if (nextLine == null) {     //且没有下一行
                    return false;
                }
                tokenizer = new StringTokenizer(nextLine);  //读入一行
            }
            return true;
        }

        public String nextLine() {
            tokenizer = new StringTokenizer("");    //清空内存中的字符
            return innerNextLine();
        }

        public String next() {
            hasNext();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }

}
